package cn.kgcv.tangccp.training;

import cn.kgc.tangcco.util.MathUtil;
import org.junit.Test;

/**
 * @author 李昊哲
 * @Description
 * @date 2020/8/17 上午11:00
 */
public class Demo02 {
    @Test
    public void test01() {
        // 计算0到10且不包含10的所有整数的和
        int sum = 0;
        for (int i = 0; i < 10; i++) {
            sum += i;
        }
        System.out.println(sum);
    }

    @Test
    public void test02() {
        int sum = MathUtil.sum(10, 0);
        System.out.println(sum);
    }

    @Test
    public void test03() {
        int[] arr0 = {0, 1, 2, 3, 4};
        int[] arr1 = {5, 6, 7, 8, 9};
        // 新数组长度为两个原数组长度的和
        int[] newArr = new int[arr0.length + arr1.length];
        // 遍历第一个数组给新数组赋值
        for (int i = 0; i < arr0.length; i++) {
            newArr[i] = arr0[i];
        }
        // 遍历第二个数组给新数组赋值
        for (int i = 0; i < arr1.length; i++) {
            newArr[i + arr0.length] = arr1[i];
        }
        System.out.print("[");
        for (int i = 0; i < newArr.length; i++) {
            System.out.print(newArr[i]);
            if (i < newArr.length - 1) {
                System.out.print(",");
            }
        }
        System.out.println("]");
    }
}
